var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var i in t) t.hasOwnProperty(i) && (e[i] = t[i]);
    })(e, t);
}, function(e, t) {
    function i() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (i.prototype = t.prototype, 
    new i());
}), a = this && this.__decorate || function(e, t, i, o) {
    var r, n = arguments.length, s = n < 3 ? t : null === o ? o = Object.getOwnPropertyDescriptor(t, i) : o;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, i, o); else for (var a = e.length - 1; 0 <= a; a--) (r = e[a]) && (s = (n < 3 ? r(s) : 3 < n ? r(t, i, s) : r(t, i)) || s);
    return 3 < n && s && Object.defineProperty(t, i, s), s;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("GameConfig"), s = e("GameData"), c = e("GameManager"), l = e("Global"), d = e("GameBlock"), u = e("GameItem"), p = cc._decorator, h = p.ccclass, f = (p.property, 
function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.HP = 1e3, e.isHurt = !1, e.isDestory = !1, e.shadow = null, e;
    }
    return i(e, t), e.prototype.init = function(i) {
        var o = this;
        return new Promise(function(t, e) {
            o.gameView || (o.gameView = c.default.getInstance().gameView), o.gameView ? o.gameView.appendSprite({
                url: i,
                root: o.gameView.layout,
                pos: cc.v2(o.node.x, o.node.y - 40)
            }).then(function(e) {
                o.sprite = e, o.sprite.node.zIndex = o.node.zIndex, o.sprite.node.angle = 0, o.sprite.node.anchorY = 0, 
                t();
            }).catch(function() {
                e();
            }) : e();
        });
    }, e.prototype.doDestroy = function() {
        var e, t;
        this.isDestory || (this.doDrop(this.getItemList()), this.isDestory = !0, this.shadow && this.gameView.removeSprite(this.shadow), 
        this.sprite && cc.Tween.stopAllByTarget(this.sprite.node), this.gameView || (this.gameView = c.default.getInstance().gameView), 
        this.gameView && (-1 == this.gameView.astar.gridsList[this.gird.x][this.gird.y].type && (this.gameView.astar.gridsList[this.gird.x][this.gird.y].type = 0, 
        this.gameView.astar.gridsList[this.gird.x][this.gird.y].target = null), this.gameView.blocks.splice(this.gameView.blocks.indexOf(this), 1), 
        this.sprite && this.gameView.removeSprite(this.sprite.node), s.GD.isVibrate && (null === (t = null === (e = GA.PA) || void 0 === e ? void 0 : e.vibrateShort) || void 0 === t || t.call(e, {})), 
        this.node.destroy()));
    }, e.prototype.doDrop = function(e) {
        for (var t = 0; t < e.length; t++) {
            var i = e[t], o = this.gameView.checkEmptyGird(this.gird.x - 3, this.gird.y - 3, this.gird.x + 3, this.gird.y + 3);
            if (!o) break;
            var r = this.gameView.getItem();
            r.setPosition(o.scaleSelf(cc.v2(this.node.width, this.node.height)).addSelf(cc.v2((this.node.width - this.gameView.map.width) / 2, (this.node.height - this.gameView.map.height) / 2))), 
            r.parent = this.node.parent, r.zIndex = 2 * -o.y, r.getComponent(u.default).init(l.ItemType.NEWYEAR, i), 
            c.default.getInstance().gameView.items.push(r.getComponent(u.default));
        }
    }, e.prototype.addShadow = function() {
        var t = this;
        this.gameView.appendSprite({
            url: "texture/battle/shadow",
            root: this.gameView.bottom,
            pos: this.node.getPosition().add(cc.v2(0, -20))
        }).then(function(e) {
            t.isDestory ? c.default.getInstance().gameView.removeSprite(e.node) : (t.shadow = e.node, 
            e.node.active = !0, e.node.scale = .7, e.node.angle = 0, e.node.zIndex = -2);
        });
    }, e.prototype.getItemList = function() {
        for (var e = [], t = 0; t < r.GC.newYearDropConfig.length; t++) {
            var i = r.GC.newYearDropConfig[t];
            if (GA.rand(0, 100) < i.percent) switch (i.type) {
              case 0:
                e.push({
                    type: i.type,
                    num: Math.floor(l.G.getPrice(s.GD.topRank - 1) * i.min / 100)
                });
                break;

              case 1:
              case 2:
                e.push({
                    type: i.type,
                    num: GA.rand(i.min, i.max)
                });
                break;

              case 4:
                e.push({
                    type: i.type,
                    idx: this.getId(),
                    time: Date.now() + r.GC.newYearGunTime
                });
            }
        }
        return 0 == e.length && e.push({
            type: 1,
            num: 50
        }), e;
    }, e.prototype.getId = function() {
        return r.GC.newYearGunIdList[GA.rand(0, r.GC.newYearGunIdList.length - 1)];
    }, a([ h ], e);
}(d.default));

n.default = f;